home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DDJMAG / DDJ8801.ZIP / NARO.ZIP / TC.ASM < prev   
Assembly Source File  |  1987-11-16  |  3KB  |  146 lines

  1.     page    60, 132
  2.     name    startup
  3.     title    LOCATE Example ROM System Startup Code
  4.     subttl    Turbo C 1.0 Version
  5.  
  6. ;
  7. ;    ROM System Startup Code for Turbo C 1.0
  8. ;    Copyright (C) 1987 by Rick Naro.  All rights reserved.
  9. ;
  10.  
  11. ;
  12. ;    Segment and group declarations
  13. ;
  14.  
  15. _text    segment byte    public    'CODE'
  16. _text    ends
  17. _etext    segment para    public    'CODEEND'
  18. _etext    ends
  19. _data    segment para    public    'DATA'
  20. _data    ends
  21. _bss    segment para    public    'BSS'
  22. _bss    ends
  23. _bssend    segment byte    public    'BSSEND'
  24. _bssend    ends
  25. _stack    segment    para    stack    'STACK'
  26. _stack    ends
  27.  
  28. dgroup    group    _data, _bss, _bssend
  29.  
  30. assume    cs:_text, ds:dgroup, ss:_stack
  31.  
  32. ;
  33. ;    This version of the startup code expects 32-bit code pointers.
  34. ;    (medium or large memory models)
  35. ;
  36.  
  37. extrn    _main : far       ; Change to near for small/compact memory model
  38.  
  39. _text    segment
  40.  
  41. public    start
  42.  
  43. start    proc    far
  44.  
  45.     cli                     ; Disable interrupts
  46.  
  47. ;
  48. ;    Initialize the stack segment and pointer
  49. ;
  50.  
  51.     mov    ax, _stack          ; Get the stack segment value
  52.     mov    ss, ax                ; Put in SS
  53.     mov    sp, offset tos        ; Load the TOS in SP
  54.  
  55. ;
  56. ;    Set up the segment registers for the initialization of DGROUP.
  57. ;    ES is initialized to DGROUP and DS is initialized to the copy of
  58. ;    DGROUP in ROM.
  59. ;
  60.  
  61.     mov    ax, dgroup          ; Get the segment for DGROUP
  62.     mov    es, ax                ; Install in ES
  63.  
  64.     mov    ax, _etext          ; Get the _etext segment
  65.     inc    ax                ; Adjust for the size of _etext
  66.     mov    ds, ax                ; Install in DS
  67.  
  68. ;
  69. ;    Copy the copy of the initialized data segment _DATA from its
  70. ;    position in ROM (just after the CODE class) to the real _DATA
  71. ;    segment in RAM.  The size of the _DATA segment is computed by
  72. ;    subtracting the start of _DATA (the label idata) from the start
  73. ;    of the next segment (the label bdata).
  74. ;
  75.  
  76.     mov    si, offset DGROUP:idata    ; Starting offset of _DATA
  77.     mov    di, si            ; Same offset, different segment
  78.     mov    cx, offset DGROUP:bdata    ; Get the end offset
  79.     sub    cx, di                   ; Subtract the two for a length
  80.     rep    movsb                   ; Copy initialized data
  81.  
  82.     push    es            ; Get the value of DGROUP
  83.     pop    ds            ; Now it is in DS
  84.  
  85. ;
  86. ;    C expects that the BSS segment is cleared when the program is
  87. ;    started.  Zero out the BSS segment within DGROUP by computing
  88. ;    the size using the label bdata and edata labels
  89. ;
  90.  
  91.     xor    al, al                   ; Use a zero fill pattern
  92.     mov    di, offset DGROUP:bdata    ; Get the starting offset
  93.     mov    cx, offset DGROUP:edata    ; Get the ending offset
  94.     sub    cx, di                   ; Subtract the two for a length
  95.     rep    stosb                   ; Zero out the BSS
  96.  
  97. ;
  98. ;    Call main and hopefully never return ...
  99. ;
  100.  
  101.     sti                ; Re-enable interrupts
  102.     call    _main            ; Call main()
  103.  
  104. ;
  105. ;    Handle a return by restarting the entire process
  106. ;
  107.  
  108.     jmp    start            ; Start all over
  109.  
  110. start    endp
  111.  
  112. _text    ends
  113.  
  114.     page
  115. _etext    segment
  116. public    tend
  117.     db    16 dup (?)        ; Force alignment of the label
  118.                     ; tend with the next paragraph
  119. tend    label    byte            ; Mark the end of the segment
  120.                     ; Do NOT change this segment
  121. _etext    ends
  122.  
  123. _data    segment
  124. public    idata
  125. idata    label    byte            ; Start of the _DATA segment
  126. _data    ends
  127.  
  128. _bss    segment
  129. public    bdata
  130. bdata    label    byte            ; Start of the _BSS (and the
  131.                     ; end of the _DATA segment
  132. _bss    ends
  133.  
  134. _bssend segment
  135. public    edata
  136. edata    label    byte            ; Mark the end of the BSS
  137. _bssend ends
  138.  
  139. _stack    segment
  140. public    tos                ; Make the TOS public
  141.     dw    256 dup (?)            ; Declare the stack size
  142. tos    label    byte            ; Define the top of stack
  143. _stack    ends
  144.  
  145.     end    start
  146.